package handlers

import (
	"github.com/gin-gonic/gin"
	"sky-build-man/models"
)

func Add(c *gin.Context) {
	title := c.PostForm("title")
	cont := c.PostForm("cont")
	img := c.PostForm("img")
	if title == "" || cont == "" || img == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "内容不能为空",
		})
		return
	}
	engin := models.Engin{
		Title: title,
		Cont:  cont,
		Img:   img,
	}
	err := models.DB.Create(&engin).Debug().Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	} else {
		c.JSON(200, gin.H{
			"code": 200,
			"msg":  "添加成功",
		})
		return
	}
}
func List(c *gin.Context) {
	var list []models.Engin
	models.DB.Find(&list)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": list,
	})
	return

}
